home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / circuits / irsim_ta.z / irsim_ta / irsim / src / ana11 / analyzer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-13  |  6.1 KB  |  327 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include "ana.h"
  17. #include "ana_glob.h"
  18.  
  19.  
  20. private    int    numAdded;
  21.  
  22.  
  23. public char *SetName( n )
  24.   register char  *n;
  25.   {
  26.     int   i;
  27.  
  28.     i = strlen( n );
  29.     if( i > max_name_len )
  30.       {
  31.     i -= max_name_len;
  32.     n += i;
  33.       }
  34.     return( n );
  35.   }
  36.  
  37.  
  38. private void AddTrace( t )
  39.   Trptr  t;
  40.   {
  41.     if( traces.first == NULL )
  42.       {
  43.     t->next = t->prev = NULL;
  44.     traces.first = traces.last = t;
  45.       }
  46.     else
  47.       {
  48.     t->next = NULL;
  49.     t->prev = traces.last;
  50.     traces.last->next = t;
  51.     traces.last = t;
  52.       }
  53.     numAdded++;
  54.   }
  55.  
  56.  
  57. public int AddNode( nd, flag )
  58.   nptr  nd;
  59.   int   flag;
  60.   {
  61.     Trptr  t;
  62.     
  63.     if( nd->nflags & DELETED )
  64.       {
  65.     fprintf( stderr, "can't watch node %s\n", nd->nname );
  66.     return( 1 );
  67.       }
  68.     if( (t = (Trptr) Valloc( sizeof( TraceEnt ) )) == NULL )
  69.       {
  70.     fprintf( stderr, "Out of memory, can't add add nd %s\n", nd->nname );
  71.     return( 0 );
  72.       }
  73.     t->name = SetName( nd->nname );
  74.     t->len = strlen( t->name );
  75.     t->bdigit = 1;
  76.     t->vector = FALSE;
  77.     t->n.nd = nd;
  78.     t->cache[0].wind = t->cache[0].cursor = &(nd->head);
  79.     AddTrace( t );
  80.     return( 1 );
  81.   }
  82.  
  83.  
  84. public int AddVector( vec, flag )
  85.   bptr  vec;
  86.   int   flag;
  87.   {
  88.     Trptr  t;
  89.     int    n;
  90.  
  91.     n = vec->nbits;
  92.     t = (Trptr) Valloc( sizeof( TraceEnt ) + sizeof( Cache ) * (n - 1) );
  93.     if( t == NULL )
  94.       {
  95.     fprintf( stderr, "Out of memory, can't add vector %s\n", vec->name );
  96.     return( 0 );
  97.       }
  98.     t->name = SetName( vec->name );
  99.     t->len = strlen( t->name );
  100.     if( flag != 0 )
  101.     t->bdigit = flag;
  102.     else
  103.     t->bdigit = ( n > 4 ) ? 4 : 1;
  104.     t->vector = TRUE;
  105.     t->n.vec = vec;
  106.     for( n--; n >= 0; n-- )
  107.     t->cache[n].wind = t->cache[n].cursor = &(vec->nodes[n]->head);
  108.     AddTrace( t );
  109.     return( 1 );
  110.   }
  111.  
  112.  
  113.  
  114. public void DisplayTraces( isMapped )
  115.   int  isMapped;
  116.   {
  117.     int  change;
  118.  
  119.     DisableInput();
  120.    
  121.     traces.total += numAdded;
  122.     numAdded = 0;
  123.  
  124.     if( not isMapped )                /* only the first time */
  125.       {
  126.     FlushTraceCache();
  127.     XMapWindow( display, window );
  128.       }
  129.     else if( not (windowState.iconified or windowState.tooSmall) )
  130.       {
  131.     change = WindowChanges();
  132.  
  133.     if( change & NTRACE_CHANGE )
  134.       {
  135.         RedrawNames( namesBox );
  136.         DrawCursVal( cursorBox );
  137.         if( change & WIDTH_CHANGE )
  138.           {
  139.         DrawScrollBar( FALSE );
  140.         RedrawTimes();
  141.           }
  142.         DrawTraces( tims.start, tims.end );
  143.       }
  144.       }
  145.  
  146.     EnableInput();
  147.   }
  148.  
  149.  
  150. public void StopAnalyzer()
  151.   {
  152.     DisableAnalyzer();
  153.   }
  154.  
  155.  
  156. public void RestartAnalyzer( first_time, last_time, same_hist )
  157.   long  first_time, last_time;
  158.   int   same_hist;
  159.   {
  160.     register Trptr  t;
  161.     register int    i, n;
  162.  
  163.     for( t = traces.first, i = traces.total; i != 0; i--, t = t->next )
  164.       {
  165.     if( t->vector )
  166.       {
  167.         for( n = t->n.vec->nbits - 1; n >= 0; n-- )
  168.           {
  169.         t->cache[n].wind = t->cache[n].cursor = 
  170.           &(t->n.vec->nodes[n]->head);
  171.           }
  172.       }
  173.     else
  174.         t->cache[0].wind = t->cache[0].cursor = &(t->n.nd->head);
  175.       }
  176.  
  177.     InitTimes( first_time, tims.steps / DEF_STEPS, last_time );
  178.     if( same_hist )
  179.     UpdateTraceCache( 0 );
  180.     else
  181.     FlushTraceCache();
  182.     EnableAnalyzer( same_hist );
  183.   }
  184.  
  185.  
  186. private void RemoveTrace( t )
  187.   Trptr  t;
  188.   {
  189.     traces.total--;
  190.     if( t == traces.first )
  191.       {
  192.     traces.first = t->next;
  193.     if( t->next )
  194.             t->next->prev = NULL;
  195.         else
  196.             traces.last = NULL;
  197.       }
  198.     else
  199.       {
  200.         t->prev->next = t->next;
  201.         if( t->next )
  202.             t->next->prev = t->prev;
  203.         else
  204.             traces.last = t->prev;
  205.       }
  206.     
  207.     if( selectedTrace == t )
  208.         selectedTrace = NULL;
  209.     Vfree( t );
  210.   }
  211.  
  212.  
  213. public void ClearTraces()
  214.   {
  215.     int  change, wasTooSmall;
  216.  
  217.     DisableInput();
  218.    
  219.     while( traces.total != 0 )
  220.     RemoveTrace( traces.first );
  221.  
  222.  
  223.     if( windowState.iconified )
  224.       {
  225.     EnableInput();
  226.     return;
  227.       }
  228.  
  229.     wasTooSmall = windowState.tooSmall;
  230.  
  231.     change = WindowChanges();
  232.     if( windowState.tooSmall )
  233.       {
  234.     RedrawSmallW();
  235.     EnableInput();
  236.     return;
  237.       }
  238.  
  239.     if( wasTooSmall )
  240.       {
  241.     RedrawBanner();
  242.     RedrawText();
  243.     DrawCursVal( cursorBox );
  244.       }
  245.     RedrawNames( namesBox );
  246.     DrawScrollBar( wasTooSmall );
  247.     RedrawTimes();
  248.     DrawTraces( tims.start, tims.end );
  249.  
  250.     EnableInput();
  251.   }
  252.  
  253.  
  254. private void UpdateWinRemove()
  255.   {
  256.     int  change;
  257.  
  258.     change = WindowChanges();
  259.  
  260.     if( change & RESIZED )
  261.         return;
  262.  
  263.     DisableInput();
  264.  
  265.     if( not (change & NTRACE_CHANGE) )          /* no trace became visible */
  266.         SetSignalPos();
  267.  
  268.     if( change & WIDTH_CHANGE )
  269.       {
  270.         DrawScrollBar( FALSE );
  271.         RedrawTimes();
  272.       }
  273.  
  274.     RedrawNames( namesBox );
  275.     DrawCursVal( cursorBox );
  276.     DrawTraces( tims.start, tims.end );
  277.  
  278.     EnableInput();
  279.   }
  280.  
  281.  
  282. public void RemoveVector( b )
  283.   bptr  b;
  284.   {
  285.     Trptr  t, tmp;
  286.     int    i = FALSE;
  287.  
  288.     for( t = traces.first; t != NULL; )
  289.       {
  290.     if( t->vector and (t->n.vec == b) )
  291.       {
  292.         tmp = t->next;
  293.         RemoveTrace( t );
  294.         t = tmp;
  295.         i = TRUE;
  296.       }
  297.     else
  298.         t = t->next;
  299.       }
  300.     if( i )
  301.     UpdateWinRemove();
  302.   }
  303.  
  304.  
  305.  
  306. public void RemoveNode( n )
  307.   nptr  n;
  308.   {
  309.     Trptr  t, tmp;
  310.     int    i;
  311.  
  312.     for( t = traces.first; t != NULL; )
  313.       {
  314.     if( not t->vector and (t->n.nd == n) )
  315.       {
  316.         tmp = t->next;
  317.         RemoveTrace( t );
  318.         t = tmp;
  319.         i++;
  320.       }
  321.     else
  322.         t = t->next;
  323.       }
  324.     if( i )
  325.     UpdateWinRemove();
  326.   }
  327.